package com.td.erhome.adapter;

import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.td.erhome.R;
import com.td.erhome.utils.ImageLoader;

import java.util.List;

import uk.co.senab.photoview.PhotoView;

/**
 * Created by Administrator on 2017/4/26 0026.
 */

public class PhotoViewPagerAdapter extends PagerAdapter {
    private List<String> mViewList;
    private Activity mContext;

    public PhotoViewPagerAdapter(List<String> mViewList, Activity activity) {
        this.mViewList = mViewList;
        this.mContext = activity;
    }

    @Override
    public int getCount() {//必须实现
        return mViewList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {//必须实现
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {//必须实现，实例化
         PhotoView im=new PhotoView(mContext);
       //  im.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
         ImageLoader.loadImage(mContext,mViewList.get(position), R.mipmap.td_moreng,im);
         container.addView(im);
         return im;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {//必须实现，销毁
        container.removeView((View) object);
    }
}
